home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / PROGS / EXAMPLES / SUBWIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  2.0 KB  |  89 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994. */
  3.  
  4. /* This program is freely distributable without licensing fees 
  5.    and is provided without guarantee or warrantee expressed or 
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. #include <GL/glut.h>
  9. #include <stdio.h>
  10.  
  11. #define GAP 10
  12.  
  13. int main_w, w1, w2, w3, w4;
  14.  
  15. void
  16. display(void)
  17. {
  18.   glClear(GL_COLOR_BUFFER_BIT);
  19.   glFlush();
  20. }
  21.  
  22. void
  23. vis(int visState)
  24. {
  25.   printf("VIS: win=%d, v=%d\n", glutGetWindow(), visState);
  26. }
  27.  
  28. void
  29. reshape(int w, int h)
  30. {
  31.   int width = 50;
  32.   int height = 50;
  33.  
  34.   glViewport(0, 0, w, h);
  35.   if (w > 50) {
  36.     width = (w - 3 * GAP) / 2;
  37.   } else {
  38.     width = 10;
  39.   }
  40.   if (h > 50) {
  41.     height = (h - 3 * GAP) / 2;
  42.   } else {
  43.     height = 10;
  44.   }
  45.   glutSetWindow(w1);
  46.   glutPositionWindow(GAP, GAP);
  47.   glutReshapeWindow(width, height);
  48.   glutSetWindow(w2);
  49.   glutPositionWindow(GAP + width + GAP, GAP);
  50.   glutReshapeWindow(width, height);
  51.   glutSetWindow(w3);
  52.   glutPositionWindow(GAP, GAP + height + GAP);
  53.   glutReshapeWindow(width, height);
  54.   glutSetWindow(w4);
  55.   glutPositionWindow(GAP + width + GAP, GAP + height + GAP);
  56.   glutReshapeWindow(width, height);
  57. }
  58.  
  59. int
  60. main(int argc, char **argv)
  61. {
  62.   glutInit(&argc, argv);
  63.   glutInitDisplayMode(GLUT_RGB);
  64.   glutInitWindowSize(210, 210);
  65.   main_w = glutCreateWindow("4 subwindows");
  66.   glutDisplayFunc(display);
  67.   glutVisibilityFunc(vis);
  68.   glutReshapeFunc(reshape);
  69.   glClearColor(1.0, 1.0, 1.0, 1.0);
  70.   w1 = glutCreateSubWindow(main_w, 10, 10, 90, 90);
  71.   glutDisplayFunc(display);
  72.   glutVisibilityFunc(vis);
  73.   glClearColor(1.0, 0.0, 0.0, 1.0);
  74.   w2 = glutCreateSubWindow(main_w, 110, 10, 90, 90);
  75.   glutDisplayFunc(display);
  76.   glutVisibilityFunc(vis);
  77.   glClearColor(0.0, 1.0, 0.0, 1.0);
  78.   w3 = glutCreateSubWindow(main_w, 10, 110, 90, 90);
  79.   glutDisplayFunc(display);
  80.   glutVisibilityFunc(vis);
  81.   glClearColor(0.0, 0.0, 1.0, 1.0);
  82.   w4 = glutCreateSubWindow(main_w, 110, 110, 90, 90);
  83.   glutDisplayFunc(display);
  84.   glutVisibilityFunc(vis);
  85.   glClearColor(1.0, 1.0, 0.0, 1.0);
  86.   glutMainLoop();
  87.   return 0;             /* ANSI C requires main to return int. */
  88. }
  89.